<html>
<head><meta charset="utf-8"><title>Brainstorming impl Trait in trait functions · t-lang · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/index.html">t-lang</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html">Brainstorming impl Trait in trait functions</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="231698925"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231698925" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231698925">(Mar 24 2021 at 19:58)</a>:</h4>
<p>I want to take people's temperature on something. </p>
<p>I would like to eventually support impl Trait in return position in traits. I don't want to argue (right now) about <em>whether</em> to do this. Let's just take it as a given that we want to for the moment. I want to brainstorm <em>how</em>.</p>
<p>The idea is that we would accept syntax like:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">trait</span><span class="w"> </span><span class="n">Foo</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">foo</span><span class="p">()</span><span class="w"> </span>-&gt; <span class="nc">impl</span><span class="w"> </span><span class="n">Trait</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">impl</span><span class="w"> </span><span class="n">Foo</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">SomeType</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">foo</span><span class="p">()</span><span class="w"> </span>-&gt; <span class="nc">impl</span><span class="w"> </span><span class="n">Trait</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="p">()</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>this is basically equivalent to a (potentially generic) associated type:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">trait</span><span class="w"> </span><span class="n">Foo</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">type</span> <span class="nc">Foo</span>: <span class="nc">Trait</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">foo</span><span class="p">()</span><span class="w"> </span>-&gt; <span class="nc">Self</span>::<span class="n">Foo</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">impl</span><span class="w"> </span><span class="n">Foo</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">SomeType</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">type</span> <span class="nc">Foo</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">impl</span><span class="w"> </span><span class="n">Trait</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">foo</span><span class="p">()</span><span class="w"> </span>-&gt; <span class="nc">Self</span>::<span class="n">Foo</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="p">()</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>But we need to describe exactly how this works. How...</p>
<ul>
<li>can users name the return type of <code>foo</code>?</li>
<li>can users bound the return type of <code>foo</code> in where clauses?</li>
</ul>
<p>This topic is a brainstorming topic, I just want to get pointers to the range of ideas that are out there.</p>



<a name="231699106"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231699106" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231699106">(Mar 24 2021 at 19:59)</a>:</h4>
<p>So, I do think in general that we should have ways of referencing the argument types and and return types of functions.</p>



<a name="231699135"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231699135" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231699135">(Mar 24 2021 at 20:00)</a>:</h4>
<p>(Beyond just <code>where</code> constraints.)</p>



<a name="231699270"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231699270" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231699270">(Mar 24 2021 at 20:00)</a>:</h4>
<p>But in particular, we <em>already</em> have the ability to write a <code>where</code> bound on a function return type, and we shouldn't lose the ability to do that just because it's an <code>impl Trait</code>.</p>



<a name="231699333"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231699333" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231699333">(Mar 24 2021 at 20:00)</a>:</h4>
<p>Here is one option: make it a literal desugaring. </p>
<p>So if we see <code>fn foo() -&gt; impl Trait</code> in a trait, we convert the method name into <code>CamelCase</code> and make an associated type. If there already is one, it's an error.</p>
<p>We pair this with a simple inference scheme for impls where if you have <code>fn foo() -&gt; Self::Foo</code> in the trait definition and <code>fn foo() -&gt; X</code> in the impl (and you don't specify <code>type Foo = ...</code>), we can take the value of <code>Foo</code> from the function.</p>



<a name="231699357"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231699357" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231699357">(Mar 24 2021 at 20:01)</a>:</h4>
<p>It should be possible to pass <code>Foo::foo</code> to something accepting a generic <code>Fn</code>, right?</p>



<a name="231699569"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231699569" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231699569">(Mar 24 2021 at 20:02)</a>:</h4>
<p>I don't think we need the desugaring to make the type directly nameable, though.</p>



<a name="231699759"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231699759" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231699759">(Mar 24 2021 at 20:03)</a>:</h4>
<p>Rather than having name transformation rules and issues with name conflicts, we could just generate an unnamed associated type.</p>



<a name="231699867"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231699867" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231699867">(Mar 24 2021 at 20:04)</a>:</h4>
<p>(Or, if we <em>did</em> want to name it, I think the name should be something like <code>Foo::foo::Self</code> or similar.</p>



<a name="231702864"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231702864" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231702864">(Mar 24 2021 at 20:26)</a>:</h4>
<p>I'm going to move something to a separate thread to avoid derailing this one.</p>



<a name="231707668"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231707668" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bstrie <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231707668">(Mar 24 2021 at 21:01)</a>:</h4>
<p><span class="user-mention silent" data-user-id="239881">Josh Triplett</span> <a href="#narrow/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions/near/231699867">said</a>:</p>
<blockquote>
<p>(Or, if we <em>did</em> want to name it, I think the name should be something like <code>Foo::foo::Self</code> or similar.</p>
</blockquote>
<p><code>Foo::foo::return</code> is easily available, although I suppose it ought to be <code>Foo::foo::Return</code> for consistency</p>



<a name="231707835"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231707835" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231707835">(Mar 24 2021 at 21:02)</a>:</h4>
<p><span class="user-mention silent" data-user-id="239881">Josh Triplett</span> <a href="#narrow/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions/near/231699357">said</a>:</p>
<blockquote>
<p>It should be possible to pass <code>Foo::foo</code> to something accepting a generic <code>Fn</code>, right?</p>
</blockquote>
<p>I don't know what this means :)</p>



<a name="231707865"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231707865" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231707865">(Mar 24 2021 at 21:02)</a>:</h4>
<p>let me start a hackmd to collect the options</p>



<a name="231708194"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231708194" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231708194">(Mar 24 2021 at 21:04)</a>:</h4>
<p><a href="https://hackmd.io/IISsYc0fTGSSm2MiMqby4A">https://hackmd.io/IISsYc0fTGSSm2MiMqby4A</a> &lt;-- take a look there</p>



<a name="231708597"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231708597" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231708597">(Mar 24 2021 at 21:07)</a>:</h4>
<p><span class="user-mention" data-user-id="127859">@Taylor Cramer</span> i feel like you've put a lot of thought into this too</p>



<a name="231708770"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231708770" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231708770">(Mar 24 2021 at 21:08)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116009">nikomatsakis</span> <a href="#narrow/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions/near/231707835">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="239881">Josh Triplett</span> <a href="#narrow/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions/near/231699357">said</a>:</p>
<blockquote>
<p>It should be possible to pass <code>Foo::foo</code> to something accepting a generic <code>Fn</code>, right?</p>
</blockquote>
<p>I don't know what this means :)</p>
</blockquote>
<p>Sorry, I should rephrase that. It should be possible to pass <code>SomeImplOfFoo::foo</code> to something accepting a generic <code>Fn</code>.</p>



<a name="231738343"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231738343" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231738343">(Mar 25 2021 at 02:14)</a>:</h4>
<p>We'd also need something like <a href="https://github.com/rust-lang/rfcs/blob/master/text/1598-generic_associated_types.md#associated-type-constructors-of-type-arguments">https://github.com/rust-lang/rfcs/blob/master/text/1598-generic_associated_types.md#associated-type-constructors-of-type-arguments</a>, right?</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">trait</span><span class="w"> </span><span class="n">Example</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">foo</span><span class="o">&lt;</span><span class="n">T</span><span class="w"> </span>: <span class="nc">Display</span><span class="o">&gt;</span><span class="w"> </span><span class="p">(</span><span class="n">it</span>: <span class="nc">T</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">impl</span><span class="w"> </span><span class="n">Display</span><span class="p">;</span><span class="w"> </span><span class="cm">/*</span>
<span class="cm">    type Foo&lt;T : Display&gt; : Display; // */</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="231767559"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231767559" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231767559">(Mar 25 2021 at 09:12)</a>:</h4>
<p><span class="user-mention" data-user-id="239881">@Josh Triplett</span> I still don't 100% know what that means -- are you saying that <code>u32::foo</code> ought to be the <em>function type</em> of the method? If so, that's interesting; I think there is a namespace clash, though, as you can currently have associated types and methods with the same names. </p>
<p>That said, this is precisely how I planned for chalk to manage questions like "which code will run when I call this method on this type". Currently in rustc this is kind of a special question, but I wanted chalk to handle it as associated type normalization.</p>



<a name="231767578"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231767578" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231767578">(Mar 25 2021 at 09:12)</a>:</h4>
<p><span class="user-mention" data-user-id="232018">@Daniel Henry-Mantilla</span> yes, I should go ahead and make the example include generics just so that is more clear.</p>



<a name="231768100"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231768100" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231768100">(Mar 25 2021 at 09:17)</a>:</h4>
<p>I updated the doc some to use better names than <code>Foo</code> and <code>foo</code> and to include GATs</p>



<a name="231771435"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231771435" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231771435">(Mar 25 2021 at 09:46)</a>:</h4>
<p>Heh, writing the examples here I'm wanting things to implement <code>Default</code></p>



<a name="231784724"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231784724" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231784724">(Mar 25 2021 at 11:35)</a>:</h4>
<p>Regarding extraction of the argument types and return type of a function, I think it should be possible to do most of it in the type system already, by using impls like</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">trait</span><span class="w"> </span><span class="n">Arg1Of</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="k">type</span> <span class="nc">Arg1</span><span class="p">;</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="k">impl</span><span class="o">&lt;</span><span class="n">A</span><span class="p">,</span><span class="w"> </span><span class="n">F</span>: <span class="nb">Fn</span><span class="o">&lt;</span><span class="p">(</span><span class="n">A</span><span class="p">,)</span><span class="o">&gt;&gt;</span><span class="w"> </span><span class="n">Arg1Of</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">F</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="k">type</span> <span class="nc">Arg1</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">A</span><span class="p">;</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="k">impl</span><span class="o">&lt;</span><span class="n">A</span><span class="p">,</span><span class="w"> </span><span class="n">B</span><span class="p">,</span><span class="w"> </span><span class="n">F</span>: <span class="nb">Fn</span><span class="o">&lt;</span><span class="p">(</span><span class="n">A</span><span class="p">,</span><span class="w"> </span><span class="n">B</span><span class="p">)</span><span class="o">&gt;&gt;</span><span class="w"> </span><span class="n">Arg1Of</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">F</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="k">type</span> <span class="nc">Arg1</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">A</span><span class="p">;</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="o">..</span><span class="p">.</span><span class="w"></span>
<span class="k">trait</span><span class="w"> </span><span class="n">Arg2Of</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="k">type</span> <span class="nc">Arg2</span><span class="p">;</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="k">impl</span><span class="o">&lt;</span><span class="n">A</span><span class="p">,</span><span class="w"> </span><span class="n">B</span><span class="p">,</span><span class="w"> </span><span class="n">F</span>: <span class="nb">Fn</span><span class="o">&lt;</span><span class="p">(</span><span class="n">A</span><span class="p">,</span><span class="w"> </span><span class="n">B</span><span class="p">)</span><span class="o">&gt;&gt;</span><span class="w"> </span><span class="n">Arg2Of</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">F</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="k">type</span> <span class="nc">Arg2</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">B</span><span class="p">;</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="o">..</span><span class="p">.</span><span class="w"></span>
</code></pre></div>
<p>The only missing piece is a means of getting the type of the whole function (i.e. the <code>fn(A) -&gt; B {T::foo}</code> type). Maybe it's possible to do this with an associated type notation like <code>{T::foo}::type</code>?</p>



<a name="231802297"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231802297" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231802297">(Mar 25 2021 at 13:44)</a>:</h4>
<p><span class="user-mention" data-user-id="271719">@Mario Carneiro</span> yes I think would be going down the path suggested <a href="https://hackmd.io/IISsYc0fTGSSm2MiMqby4A#Introduce-an-associated-type-for-the-function-type">here</a> in the brainstorming doc, right? Or do I misunderstand?</p>



<a name="231814993"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231814993" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231814993">(Mar 25 2021 at 14:53)</a>:</h4>
<blockquote>
<p>But we need to describe exactly how this works. How...</p>
<ul>
<li>can users name the return type of foo?</li>
<li>can users bound the return type of foo in where clauses?</li>
</ul>
<p>This topic is a brainstorming topic, I just want to get pointers to the range of ideas that are out there.</p>
</blockquote>
<p>I feel like I am missing something; how is this specific to impl Trait in trait functions? Don't the exact same questions come up for inherent or free-standing functions?</p>



<a name="231830194"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231830194" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Cramer <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231830194">(Mar 25 2021 at 16:12)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> <code>impl Trait</code> functions are special in that the return type is generally unnameable</p>



<a name="231830411"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231830411" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Cramer <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231830411">(Mar 25 2021 at 16:14)</a>:</h4>
<p>gonna drop the RFC that I wrote ages ago in here, which handled this by allowing associated types to be inferred from function signatures: <br>
<a href="https://github.com/cramertj/impl-trait-goals/blob/impl-trait-in-traits/0000-impl-trait-in-traits.md">https://github.com/cramertj/impl-trait-goals/blob/impl-trait-in-traits/0000-impl-trait-in-traits.md</a></p>



<a name="231830816"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231830816" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Cramer <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231830816">(Mar 25 2021 at 16:16)</a>:</h4>
<p><span class="user-mention" data-user-id="119009">@eddyb</span> 's favorite solution to this used to be "just add <code>typeof</code>"</p>



<a name="231830888"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231830888" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231830888">(Mar 25 2021 at 16:16)</a>:</h4>
<p><span class="user-mention silent" data-user-id="127859">Taylor Cramer</span> <a href="#narrow/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions/near/231830194">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="120791">RalfJ</span> <code>impl Trait</code> functions are special in that the return type is generally unnameable</p>
</blockquote>
<p>yes but this thread here makes it sounds like <code>impl Trait</code> functions <em>in traits</em> are somehow even more special.<br>
They certainly are in terms of requiring Generic Associated Types, but I see no connection to the questions I quoted.</p>



<a name="231832494"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231832494" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bstrie <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231832494">(Mar 25 2021 at 16:27)</a>:</h4>
<blockquote>
<p>"just add typeof"</p>
</blockquote>
<p>That doesn't feel right to me, I would expect <code>typeof(MyTrait::my_fn)</code> to be something like <code>fn(foo)-&gt;bar</code>, not <code>bar</code>.</p>



<a name="231836132"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231836132" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Cramer <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231836132">(Mar 25 2021 at 16:49)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> outside of traits, you can use <code>type X = impl Trait;</code> if you need a nameable thing (at least, you will once it's stable)</p>



<a name="231836205"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231836205" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Cramer <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231836205">(Mar 25 2021 at 16:49)</a>:</h4>
<p><span class="user-mention" data-user-id="256342">@bstrie</span> right, it would be <code>typeof(MyTrait::my_fn)::Output</code></p>



<a name="231836374"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231836374" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231836374">(Mar 25 2021 at 16:50)</a>:</h4>
<p><span class="user-mention silent" data-user-id="127859">Taylor Cramer</span> <a href="#narrow/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions/near/231836132">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="120791">RalfJ</span> outside of traits, you can use <code>type X = impl Trait;</code> if you need a nameable thing (at least, you will once it's stable)</p>
</blockquote>
<p>ah okay, yes taking unstable features into account this makes more sense</p>



<a name="231836588"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231836588" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231836588">(Mar 25 2021 at 16:51)</a>:</h4>
<p>is there no good way to use a similar approach even inside traits?</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">trait</span><span class="w"> </span><span class="n">Foo</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">  </span><span class="k">type</span> <span class="nc">T</span>: <span class="nc">Trait</span><span class="p">;</span><span class="w"> </span><span class="k">fn</span> <span class="nf">foo</span><span class="p">()</span><span class="w"> </span>-&gt; <span class="nc">Self</span>::<span class="n">T</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">impl</span><span class="w"> </span><span class="n">Foo</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">X</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">  </span><span class="k">type</span> <span class="nc">T</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">impl</span><span class="w"> </span><span class="n">Trait</span><span class="p">;</span><span class="w"></span>
<span class="w">  </span><span class="k">fn</span> <span class="nf">foo</span><span class="p">()</span><span class="w"> </span>-&gt; <span class="nc">Self</span>::<span class="n">T</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="o">..</span><span class="p">.</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="231836597"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231836597" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231836597">(Mar 25 2021 at 16:51)</a>:</h4>
<p><span class="user-mention silent" data-user-id="127859">Taylor Cramer</span> <a href="#narrow/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions/near/231830816">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="119009">eddyb</span> 's favorite solution to this used to be "just add <code>typeof</code>"</p>
</blockquote>
<p>I don't consider this a real solution</p>



<a name="231836610"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231836610" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231836610">(Mar 25 2021 at 16:51)</a>:</h4>
<p>but I should elaborate why :)</p>



<a name="231836623"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231836623" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231836623">(Mar 25 2021 at 16:51)</a>:</h4>
<p>also, I shouldn't talk like that :P</p>



<a name="231836637"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231836637" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231836637">(Mar 25 2021 at 16:51)</a>:</h4>
<p>let me rephrase: I see a lot of challenges with that approach</p>



<a name="231836736"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231836736" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231836736">(Mar 25 2021 at 16:52)</a>:</h4>
<p>among other things, you have to do <code>typeof</code> with <em>some expression</em>, which means it needs arguments etc</p>



<a name="231836771"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231836771" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231836771">(Mar 25 2021 at 16:52)</a>:</h4>
<p>I also don't know how this can express higher-ranked things</p>



<a name="231836882"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231836882" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Cramer <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231836882">(Mar 25 2021 at 16:53)</a>:</h4>
<p>Yes, it's also not my preferred approach, but I thought it was worth voicing.</p>



<a name="231836904"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231836904" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231836904">(Mar 25 2021 at 16:53)</a>:</h4>
<p><span class="user-mention silent" data-user-id="120791">RalfJ</span> <a href="#narrow/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions/near/231836588">said</a>:</p>
<blockquote>
<p>is there no good way to use a similar approach even inside traits?</p>
</blockquote>
<p>this is what I aim to stabilize first, but I want an ergonomic way. More generally, I want to get as close to "impl Trait everywhere" and "async fn everywhere" as we can -- perhaps that's misleading -- but I mean that impl Trait should be usable where it make sense to use it. I think it makes sense in traits.</p>



<a name="231836923"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231836923" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231836923">(Mar 25 2021 at 16:53)</a>:</h4>
<p>(deleted)</p>



<a name="231836962"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231836962" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231836962">(Mar 25 2021 at 16:53)</a>:</h4>
<p><span class="user-mention silent" data-user-id="127859">Taylor Cramer</span> <a href="#narrow/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions/near/231836882">said</a>:</p>
<blockquote>
<p>Yes, it's also not my preferred approach, but I thought it was worth voicing.</p>
</blockquote>
<p>agreed,I should add it to the doc</p>



<a name="231837077"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231837077" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231837077">(Mar 25 2021 at 16:54)</a>:</h4>
<p><span class="user-mention silent" data-user-id="127859">Taylor Cramer</span> <a href="#narrow/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions/near/231830411">said</a>:</p>
<blockquote>
<p>gonna drop the RFC that I wrote ages ago in here, which handled this by allowing associated types to be inferred from function signatures: <br>
<a href="https://github.com/cramertj/impl-trait-goals/blob/impl-trait-in-traits/0000-impl-trait-in-traits.md">https://github.com/cramertj/impl-trait-goals/blob/impl-trait-in-traits/0000-impl-trait-in-traits.md</a></p>
</blockquote>
<p>so...</p>



<a name="231837117"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231837117" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231837117">(Mar 25 2021 at 16:54)</a>:</h4>
<p>I suppose that a "middle ground" would be not to have a way to name the associated type in the trait</p>



<a name="231837138"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231837138" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231837138">(Mar 25 2021 at 16:54)</a>:</h4>
<p>but just guarantee that one could refactor to use a named type if desired</p>



<a name="231837180"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231837180" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231837180">(Mar 25 2021 at 16:55)</a>:</h4>
<p>but I think that's going to be problematic when you extend to <code>async fn</code></p>



<a name="231837298"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231837298" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bstrie <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231837298">(Mar 25 2021 at 16:55)</a>:</h4>
<p><span class="user-mention silent" data-user-id="127859">Taylor Cramer</span> <a href="#narrow/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions/near/231836205">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="256342">bstrie</span> right, it would be <code>typeof(MyTrait::my_fn)::Output</code></p>
</blockquote>
<p>is the idea that <code>typeof</code> would be more generally useful in other contexts? because that already seems fairly magical, and if there's magic involved then it seems like you could just support <code>MyTrait::my_fn::Output</code> outright</p>



<a name="231837307"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231837307" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231837307">(Mar 25 2021 at 16:55)</a>:</h4>
<p>am I right <span class="user-mention" data-user-id="127859">@Taylor Cramer</span> that this is the conclusion of the draft RFC? I didn't actually read it :P</p>



<a name="231837862"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231837862" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231837862">(Mar 25 2021 at 16:58)</a>:</h4>
<p>I added <code>type_of</code></p>



<a name="231838745"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231838745" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231838745">(Mar 25 2021 at 17:03)</a>:</h4>
<p>I also expanded the argument in the doc, <span class="user-mention" data-user-id="120791">@RalfJ</span>, to lay out my case for why this is important and how it fits in :)</p>



<a name="231839427"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231839427" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231839427">(Mar 25 2021 at 17:07)</a>:</h4>
<p>reading your RFC, <span class="user-mention" data-user-id="127859">@Taylor Cramer</span>, I was confused by one thing</p>



<a name="231839431"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231839431" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231839431">(Mar 25 2021 at 17:07)</a>:</h4>
<p>you wrote:</p>



<a name="231839480"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231839480" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231839480">(Mar 25 2021 at 17:07)</a>:</h4>
<p>oh, i get it</p>



<a name="231839502"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231839502" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231839502">(Mar 25 2021 at 17:07)</a>:</h4>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">impl</span><span class="w"> </span><span class="n">Foo</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">MyType</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">foo</span><span class="p">()</span><span class="w"> </span>-&gt; <span class="kp">&amp;</span><span class="o">'</span><span class="nb">static</span> <span class="kt">str</span> <span class="p">{</span><span class="w"> </span><span class="s">"foo!"</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="231839528"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231839528" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231839528">(Mar 25 2021 at 17:07)</a>:</h4>
<p>users can write that even with <code>fn foo() -&gt; impl Debug</code> in the trait definition, is your point</p>



<a name="231840214"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231840214" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231840214">(Mar 25 2021 at 17:11)</a>:</h4>
<p>ok, I integrated the RFC more into my hackmd</p>



<a name="231842567"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231842567" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Cramer <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231842567">(Mar 25 2021 at 17:26)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> personally, I actually think <code>async fn</code> probably deserves it's "own thing" for this</p>



<a name="231842587"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231842587" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Cramer <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231842587">(Mar 25 2021 at 17:26)</a>:</h4>
<p>along with <code>gen fn</code> and <code>async gen fn</code></p>



<a name="231842714"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231842714" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Cramer <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231842714">(Mar 25 2021 at 17:27)</a>:</h4>
<p>I think the principles that apply generally to "<code>impl Trait</code> in traits" weight differently in my mind WRT <code>async fn</code></p>



<a name="231842989"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231842989" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231842989">(Mar 25 2021 at 17:29)</a>:</h4>
<p>well, keep in mind that <code>async fn</code> is maximal in the sense of its capture, and afaik the recommended workaround is to use <code>impl Trait</code></p>



<a name="231842999"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231842999" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231842999">(Mar 25 2021 at 17:29)</a>:</h4>
<p>I don't really see them as all that different</p>



<a name="231843031"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231843031" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231843031">(Mar 25 2021 at 17:29)</a>:</h4>
<p>but also, if we have something for <code>async fn</code>, wouldn't it likely also be applicable to <code>impl Trait</code>?</p>



<a name="231843056"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231843056" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231843056">(Mar 25 2021 at 17:29)</a>:</h4>
<p>like, is there a <em>downside</em> to limiting it?</p>



<a name="231843081"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231843081" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231843081">(Mar 25 2021 at 17:29)</a>:</h4>
<p>one other factor is wanting to apply <code>Send</code> to many associated types at once</p>



<a name="231843098"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231843098" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231843098">(Mar 25 2021 at 17:29)</a>:</h4>
<p>you probably want <em>all</em> or <em>none</em> of the associated types to be <code>Send</code></p>



<a name="231843347"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231843347" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Cramer <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231843347">(Mar 25 2021 at 17:31)</a>:</h4>
<p>Right, and for the same trait, it would be useful in some places to have it be <code>Send</code>, and in others for it to be non-<code>Send</code></p>



<a name="231843402"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231843402" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Cramer <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231843402">(Mar 25 2021 at 17:31)</a>:</h4>
<p>(not for the same end-consumer binary, typically, but for multiple users of a library, some using singlethreaded and some using multithreaded computations)</p>



<a name="231843531"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231843531" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Cramer <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231843531">(Mar 25 2021 at 17:32)</a>:</h4>
<p>And then you quickly want the ability to write bounds like <code>A: SendIfSend&lt;B&gt;</code></p>



<a name="231843650"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231843650" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Cramer <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231843650">(Mar 25 2021 at 17:32)</a>:</h4>
<p>which we glossed over before by allowing <code>impl Trait</code> to leak auto traits</p>



<a name="231843957"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231843957" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Cramer <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231843957">(Mar 25 2021 at 17:34)</a>:</h4>
<p>The reason I think <code>async fn</code> is special is that, when everything you're doing is <code>async</code>/<code>await</code>, the resulting value doesn't "feel" like a future</p>



<a name="231843975"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231843975" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231843975">(Mar 25 2021 at 17:34)</a>:</h4>
<p>Right. I guess the question is if you are likely to want that applied <em>only</em> to the results from <code>async fn</code> (and not other <code>impl Trait</code>), etc. Maybe!</p>



<a name="231843987"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231843987" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Cramer <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231843987">(Mar 25 2021 at 17:35)</a>:</h4>
<p>But I'm not sure how much to push on that post-rigorous understanding</p>



<a name="231844032"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231844032" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231844032">(Mar 25 2021 at 17:35)</a>:</h4>
<p>I think that may be an argument for some other way to reduce the amount of "capture" from an <code>async fn</code></p>



<a name="231844099"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231844099" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Cramer <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231844099">(Mar 25 2021 at 17:35)</a>:</h4>
<p>other than writing an async block inside of a function that returns an <code>impl Future</code>, you mean?</p>



<a name="231844164"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231844164" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231844164">(Mar 25 2021 at 17:36)</a>:</h4>
<p>Right, because if we're treating <code>async fn</code> specially, you then lose that specialness when you do that rewrite.</p>



<a name="231844871"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231844871" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Cramer <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231844871">(Mar 25 2021 at 17:40)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> Makes sense. To disagree with my earlier self, I also tend to think that <code>async fn</code> as "just a fn, but async" leads to a lot of unnecessary confusion</p>



<a name="231844928"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231844928" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Cramer <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231844928">(Mar 25 2021 at 17:41)</a>:</h4>
<p>That is, the post-rigorous understanding quite often falls apart</p>



<a name="231844951"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231844951" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231844951">(Mar 25 2021 at 17:41)</a>:</h4>
<p>I guess I feel like I'd <em>like</em> to be able to name the returns of <code>impl Trait</code>, at least</p>



<a name="231844976"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231844976" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231844976">(Mar 25 2021 at 17:41)</a>:</h4>
<p>I'd also like to understand that better, <span class="user-mention" data-user-id="127859">@Taylor Cramer</span></p>



<a name="231845002"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231845002" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231845002">(Mar 25 2021 at 17:41)</a>:</h4>
<p>I want status quo user stories about this :)</p>



<a name="231845004"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231845004" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Cramer <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231845004">(Mar 25 2021 at 17:41)</a>:</h4>
<p>Agreed, and specifically for <code>async fn</code> you'd like to not have to introduce a new name in the trait definition explicitly, right?</p>



<a name="231845011"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231845011" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231845011">(Mar 25 2021 at 17:41)</a>:</h4>
<p>what are the edges</p>



<a name="231845087"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231845087" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231845087">(Mar 25 2021 at 17:42)</a>:</h4>
<p><span class="user-mention silent" data-user-id="127859">Taylor Cramer</span> <a href="#narrow/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions/near/231845004">said</a>:</p>
<blockquote>
<p>Agreed, and specifically for <code>async fn</code> you'd like to not have to introduce a new name in the trait definition explicitly, right?</p>
</blockquote>
<p>right-- it's true that for other impl Trait htat might be good enough, esp. if it can be done backwards compatibly</p>



<a name="231845201"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231845201" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Cramer <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231845201">(Mar 25 2021 at 17:42)</a>:</h4>
<p>Right, I think for other <code>impl Trait</code>-in-traits I tend to think that it either doesn't need to be named, or you can be bothered to give it a decent name :)</p>



<a name="231845268"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231845268" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Cramer <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231845268">(Mar 25 2021 at 17:43)</a>:</h4>
<p>but I understand why in the <code>async fn</code> case that can be really quite annoying</p>



<a name="231845403"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231845403" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Cramer <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231845403">(Mar 25 2021 at 17:44)</a>:</h4>
<p>though I think I do actually believe that if you're doing tricksy things like limiting the amount of captures available to a returned <code>-&gt; impl Future</code>, perhaps we could require you  to write out the associated type definition in that case.</p>



<a name="231845472"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231845472" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Cramer <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231845472">(Mar 25 2021 at 17:44)</a>:</h4>
<p>Which would mean the special case really is <code>async fn</code></p>



<a name="231845537"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231845537" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Cramer <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231845537">(Mar 25 2021 at 17:45)</a>:</h4>
<p>I don't know-- I certainly haven't convinced myself of any particular path :)</p>



<a name="231855314"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231855314" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231855314">(Mar 25 2021 at 18:45)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116009">nikomatsakis</span> <a href="#narrow/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions/near/231767559">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="239881">Josh Triplett</span> I still don't 100% know what that means -- are you saying that <code>u32::foo</code> ought to be the <em>function type</em> of the method?</p>
</blockquote>
<p>No, that wasn't what I was asking about. Let me write out a complete example...</p>



<a name="231855787"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231855787" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231855787">(Mar 25 2021 at 18:48)</a>:</h4>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">trait</span><span class="w"> </span><span class="n">Foo</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">foo</span><span class="p">()</span><span class="w"> </span>-&gt; <span class="nc">impl</span><span class="w"> </span><span class="n">Trait</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">impl</span><span class="w"> </span><span class="n">Foo</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">SomeType</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">foo</span><span class="p">()</span><span class="w"> </span>-&gt; <span class="nc">impl</span><span class="w"> </span><span class="n">Trait</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="p">()</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">call_func</span><span class="o">&lt;</span><span class="n">T</span>: <span class="nc">Trait</span><span class="p">,</span><span class="w"> </span><span class="n">F</span>: <span class="nb">FnOnce</span><span class="p">()</span><span class="w"> </span>-&gt; <span class="nc">T</span><span class="o">&gt;</span><span class="p">(</span><span class="n">func</span>: <span class="nc">F</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">func</span><span class="p">();</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">call_func</span><span class="p">(</span><span class="n">SomeType</span>::<span class="n">foo</span><span class="p">);</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="231855896"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231855896" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231855896">(Mar 25 2021 at 18:49)</a>:</h4>
<p>Assuming you can do <code>-&gt; impl Trait</code> in a trait, the above code should be valid.</p>



<a name="231855965"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231855965" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231855965">(Mar 25 2021 at 18:49)</a>:</h4>
<p>And once you can write <em>that</em>, you can name the return type as <code>T</code> within <code>call_func</code>. You can also further constrain the return type, via bounds on <code>T</code>.</p>



<a name="231856540"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231856540" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231856540">(Mar 25 2021 at 18:53)</a>:</h4>
<p>I think it'd be reasonable to add syntactic sugar to go from the trait to the function's type in type space, not just in value space.</p>



<a name="231857597"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231857597" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231857597">(Mar 25 2021 at 18:59)</a>:</h4>
<p>I was suggesting, if it'd be feasible, that we could allow access to the type namespace through a value of the type (so, if <code>x</code> is a <code>u32</code>, allow <code>x::MAX</code>). That would then make <code>SomeType::foo::Output</code> work.</p>



<a name="231857722"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/231857722" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#231857722">(Mar 25 2021 at 19:00)</a>:</h4>
<p>Or, for that matter, once you have <code>T: Foo</code>, you could write <code>T::foo::Output</code>.</p>



<a name="232004754"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/232004754" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#232004754">(Mar 26 2021 at 17:34)</a>:</h4>
<p>I wrote up various proposals along those lines</p>



<a name="232004763"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/232004763" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#232004763">(Mar 26 2021 at 17:34)</a>:</h4>
<p>I think they have downsides</p>



<a name="232478499"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Brainstorming%20impl%20Trait%20in%20trait%20functions/near/232478499" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions.html#232478499">(Mar 30 2021 at 18:58)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116009">nikomatsakis</span> <a href="#narrow/stream/213817-t-lang/topic/Brainstorming.20impl.20Trait.20in.20trait.20functions/near/231699333">said</a>:</p>
<blockquote>
<p>We pair this with a simple inference scheme for impls where if you have <code>fn foo() -&gt; Self::Foo</code> in the trait definition and <code>fn foo() -&gt; X</code> in the impl (and you don't specify <code>type Foo = ...</code>), we can take the value of <code>Foo</code> from the function.</p>
</blockquote>
<p>This would be really nice <span aria-label="+1" class="emoji emoji-1f44d" role="img" title="+1">:+1:</span> -- it'd make common things like <code>impl Add for Blah</code> so much simpler too.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>